package cc.idoone.spring_boot_hello.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <h3>WebServlet 测试</h3>
 * <p>
 * 需要在启动入口处添加一个核心的注解@ServletComponentScan
 * </p>
 * <p>
 * 方式二：定义Bean: ServletRegistrationBean(参考 ApplicationConfiguration)
 * </p>
 *
 * @author hemj
 * @version 2017/9/22
 */
@WebServlet(name = "HelloServlet", urlPatterns = "/hello/servlet")
public class HelloServlet extends HttpServlet {

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.getWriter().print("hello servlet");
		resp.getWriter().flush();
		resp.getWriter().close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
